package demo.adapter;

import demo.zandroid.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class TestSpringListViewAdapter extends BaseAdapter {

	private Context context;
	private String[] data;

	public TestSpringListViewAdapter(Context context, String[] data) {
		super();
		this.context = context;
		this.data = data;
	}

	public TestSpringListViewAdapter() {
		super();
	}

	@Override
	public int getCount() {
		return data.length;
	}

	@Override
	public Object getItem(int position) {
		return data[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder = null;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(
					R.layout.activity_testspring_lv_item, null);
			holder.tv = (TextView) convertView.findViewById(R.id.tv_title);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		String str = data[position];
		holder.tv.setText(str);
		return convertView;
	}

	class ViewHolder {
		TextView tv;
	}
}
